/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Server.DAO.MSSQLConnect;
import Server.QLKS_Interface;
import java.awt.Frame;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import javax.swing.JFrame;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.swing.JRViewer;

/**
 *
 * @author PEKEM
 */
public class ShowReport extends JFrame{
    String ServerURL;
    QLKS_Interface QI;
    MSSQLConnect cn = new MSSQLConnect();
    public static void main(String[] args) throws Exception {
        
    }
    public Connection getConnection() throws ClassNotFoundException, SQLException, Exception { 
        return cn.getConnect();
    }
    public void Show_ReportDoanhThu(String thang) throws JRException, ClassNotFoundException, SQLException, Exception{
        ServerURL = "qlks";
        try {
            QI = (QLKS_Interface) Naming.lookup(ServerURL);
        } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        }       
        JRViewer viewer = new JRViewer(QI.ShowBaoCao(thang));            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void Show_ReportPhieuThue(String makhach) throws RemoteException{
        ServerURL = "qlks";
        try {
            QI = (QLKS_Interface) Naming.lookup(ServerURL);
        } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        }
        JRViewer viewer = new JRViewer(QI.ShowPhieuThuePhong(makhach));            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void Show_ReportHoaDon(String makhach) throws RemoteException{
        ServerURL = "qlks";
        try {
            QI = (QLKS_Interface) Naming.lookup(ServerURL);
        } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        }
        JRViewer viewer = new JRViewer(QI.ShowHoaDon(makhach));            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    public void Show_ReportDatTiecRMI(String mapdt) throws RemoteException{
        ServerURL = "qlks";
        try {
            QI = (QLKS_Interface) Naming.lookup(ServerURL);
        } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        }
        JRViewer viewer = new JRViewer(QI.ShowPhieuDatTiec(mapdt));            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    public void Show_ReportDatTiec(String mapdt) throws JRException, ClassNotFoundException, SQLException, Exception{
        JasperReport report = JasperCompileManager.compileReport("src\\report\\datiec.jrxml");
        HashMap parameters = new HashMap();
        parameters.put("mapdt", mapdt);
        JasperPrint print = JasperFillManager.fillReport(report, parameters, getConnection());
        System.out.println(report.getQuery().toString());
        JRViewer viewer = new JRViewer(print);            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
}
